<?php 
	/**
	 * 主程序，每日抓取最新数据，并提取和入库
	 */
	header("Content-Type:text/html;charset=utf-8");
	include_once dirname(dirname(__FILE__))."/include/common.inc.php";
	include_once dirname(dirname(__FILE__))."/baidu/function.beta.php";
	$global_site = "baidu";
	
	$global_site = "baidu";
	date_default_timezone_set('PRC');
	$number = 5;
	//取得近义词
	$relate = getRelateWord('u');
	$find = $relate['find'];
	$replace = $relate['replace'];
	
	$i =0;
	$body = '';
	while($i <$number){
		$a = getOneblog();
		$title[$i] = $a->title;
		$body .= $a->body;
		$id[$i] = $a->id;
		//$joke[$i] = getOneJoke();
		$msg[$i]  = getOneMsg();
		$i++;
	}
	//var_dump($body);
	preg_match_all('%(<p.*?>[\s\S]*?</p>)%i', $body,$matches);
	$totalp = count($matches[1]);
	//echo $totalp;
	//echo "\n";
	shuffle($matches[1]);
	$num = ceil($totalp/$number);
	$finall = array_chunk($matches[1], $num);
	$i = 0;
	foreach($finall as $key=>$value){
		$body= implode('',$value);
		$suid = array_rand($value);
		$summary = $value[$suid];
		
		$body = str_replace($find, $replace,$body);
		$thistitle = $title[$i];
		$joke = getOneJoke();
		$body = '笑话:<br>'.$joke."<br>".$body;
		$ad = getOneAd();
		$ad = iconv('gbk','utf-8',$ad);
		$body = $ad."<br>".$body;
		
		$body = $body.'<p>早安好：<br />'.$msg[$i].'</p>';
		//$body = $body.getOneSite();
		
		//$search = array('wowawowa.cn','我哇',);
		//$replace = array('jimeishuo.com','即美说');
		//$body = str_replace($search,$replace,$body);
		$body = preg_replace('/[\s]{2,}/','',$body);
		$body = str_replace('\r\n','<br>',$body);
		$body = str_replace('wowawowa.cn','jimeishuo.com',$body);
		$body = str_ireplace('ssNN.net','jimeishuo.com',$body);
		$body = str_replace('我哇','即美说',$body);
		$body = str_replace('lady8844','即美说减肥网',$body);
		$thistitle = str_replace('lady8844','即美说减肥网',$thistitle);
		$thistitle = str_replace('爱美网','',$thistitle);
		//$body = str_replace('src="/collection/uploads/allimg/','src="http://www.jimeishuo.com/uploads/allimg/',$body);
		$body = str_replace('src="/caiji/uploads/allimg/','src="http://www.jimeishuo.com/uploads/allimg/',$body);
	
		beta24_post('默认分类',$thistitle,$summary, $body);
		//update_archive($id[$i]);
		$i++;
		sleep(30);
		//exit;
	}
	
	 
?>